<?php
namespace App\Util;

class PageHelper {

    /**
     * @author gaoyoulong
     * @param $list
     * @return array|\Illuminate\Support\Collection
     */
    public static function showFrontPage($list) {
        $pages = collect([]);
        for ($i = 1; $i <= $list->lastPage(); $i++) {
            $pages->push($i);
        }
        $currentPage = $list->currentPage();
        $showNum = 5;
        $p = ceil($currentPage / $showNum);
        $pages = $pages->forPage($p, $showNum)->all();
        return $pages;
    }


    public static function showApiResult($list){
        $result = [
            'list'=> $list->toArray()['data'],
            'more'=> $list->hasMorePages(),
            'next'=> $list->hasMorePages() ? $list->currentPage()+1 : 0
        ];

        return $result;
    }
}